import { FC } from "react";
import { QuestionTitlePropsType, QuestionTitleDefaultProps } from "./interface";
import { Typography } from "antd";

const { Title } = Typography;
const QuestionTitle: FC<QuestionTitlePropsType> = (
  props: QuestionTitlePropsType
) => {
  const {
    text = "",
    level = 1,
    isCenter = false,
  } = {
    ...QuestionTitleDefaultProps,
    ...props,
  };

  //计算字体
  const getFontSize = (level: number = 3) => {
    const initNumber = 28;
    return initNumber - level * 4 + "px";
  };

  return (
    <>
      <Title
        level={level}
        style={{
          textAlign: isCenter ? "center" : "start",
          marginBottom: 0,
          fontSize: getFontSize(level),
        }}
      >
        {text}
      </Title>
    </>
  );
};

export default QuestionTitle;
